package net.hzlj.platform.enterprise.common;

import java.lang.ref.WeakReference;
import android.os.Handler;
import android.os.Message;

/**
 * @ClassName: WeakReferenceHandler
 * @Description: Handler模板类,所有的Handler都必须继承实现,这样可以防止在Activity或者Fragment中传入context造成的内存泄露
 * @Author: Jason.Zhang zhangyujn1989ok@gmail.com
 * @Date: 2016-1-8 14:14:30
 */
public abstract class WeakReferenceHandler<T> extends Handler{

	/** 外部弱引用*/
	protected WeakReference<T> mReference;
	
	public WeakReferenceHandler(T reference){
		mReference = new WeakReference<T>(reference);
	}

	@Override
	public void handleMessage(Message msg) {
		if (mReference.get() == null){
			return;
		}
		handleMessage(mReference.get(), msg);
	}
	
	protected abstract void handleMessage(T reference, Message msg);
	
}
